﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using Sharp.Infrastructure;

namespace Sharp.Portal.Configuration
{

    /// <summary>
    /// 自定义列的配置管理
    /// </summary>
    public class DataConfigManage
    {
        /// <summary>
        /// 获取自定义列配置
        /// </summary>
        /// <returns></returns>
        public static List<KeyValue<string, string>> GetData()
        {
            var list =
                   SerializableHelper.DeSerialize<List<KeyValue<string, string>>>(new FileInfo(HttpContext.Current.Server.MapPath("~/App_Data/DataConfig.json"))
                   , DataFormart.Json);
            if (list == null)
            {
                list = new List<KeyValue<string, string>>();
            }
            return list;
        }
        /// <summary>
        /// 保存自定义列配置
        /// </summary>
        /// <param name="list"></param>
        public static void Save(List<KeyValue<string, string>> list)
        {
            //去掉空白项
            list = list
                .Where(x =>
                    !string.IsNullOrEmpty(x.Key) &&
                    !string.IsNullOrEmpty(x.Value)).ToList();

            SerializableHelper.Serialize(list, HttpContext.Current.Server.MapPath("~/App_Data/DataConfig.json"));
        }

    }
}
